home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoPageDeallocation.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.0 KB  |  222 lines

  1. /*
  2.  *   $RCSfile: undoPageDeallocation.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "openlog.h"
  60. #include "logrecs.h"
  61. #include "trans.h"
  62. #include "bitmap.h"
  63. #include "undo.h"
  64. #include "io_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "bm_extfuncs.h"
  67. #include "log_extfuncs.h"
  68. #include "undo_extfuncs.h"
  69. #include "logaction.h"
  70. #include "util_funcs.h"
  71. #include "thread_globals.h"
  72.  
  73.  
  74.  void
  75. undoPageDeallocation (
  76.  
  77.     LOGRECORDHDR        *recordHeader 
  78. )
  79. {
  80.  
  81.     register VOLREC        *volRec;
  82.     register PID        *pidList;
  83.     LIST                bitmapList;
  84.     LOGRECORDINFO        recordInfo;
  85.     FORCEMARK            forceMark;
  86.     LSN                    lsn;
  87.     LRC                 *lrcList;
  88.     LRC                 lrcShortList[LRC_SHORTLIST_SIZE];
  89.     int                 lrcCount;
  90.     LRC                 *headerLRC; /* LRC on volume header */
  91.     PAGEALLOCINFO        pageAllocInfo;
  92.  
  93.  
  94.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
  95.  
  96.     /*
  97.      *    get a pointer to the common page allocation info
  98.      *    Copy it to a separate area so that it can be updated
  99.      */
  100.     pageAllocInfo = *(PAGEALLOCINFO *) GET_LOG_IMAGE(recordHeader, 0);
  101.     TRPRINT(TR_IO, TR_LEVEL_2, ("numPages:%d", pageAllocInfo.numPages));
  102.  
  103.     /*
  104.      *    get a pointer to the name in the record
  105.      */
  106.     pidList = (PID *) GET_LOG_IMAGE(recordHeader, 1);
  107.     TRPRINT(TR_IO, TR_LEVEL_2, ("pid:%d", pidList->page));
  108.  
  109.     if ((volRec = io_FindVolRec(pidList->volid)) == NULL)    {
  110.  
  111.         SM_ERROR(TYPE_FATAL, Active->errno);
  112.     }
  113.     if (waitSemaphore(&(volRec->headerLink->pageHash->semaphore)) != esmNOERROR)  {
  114.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  115.     }
  116.  
  117.     /*
  118.      *    intialize the bitmap list
  119.      */
  120.     initializeList( &(bitmapList) );
  121.  
  122.     /*
  123.      *    Reallocate the page
  124.      */
  125.     if (io_ReallocPages(pageAllocInfo.page2size, 
  126.         (int) pageAllocInfo.numPages, pidList, &bitmapList))    {
  127.  
  128.         SM_ERROR(TYPE_FATAL, Active->errno);
  129.     }
  130.  
  131.     /*
  132.      *  increment the lrc on each bitmap page, and count the
  133.      *  number of bitmap pages
  134.      */
  135.     bm_ListIncrementCount(&bitmapList, &lrcCount);
  136.  
  137.     /*
  138.      *  Create the lrcList.  If its short, use the one on the stack,
  139.      *  otherwise malloc space and remember to free it before returning.
  140.      *  This is necessary, because the list could potentially be very
  141.      *  large, but usually it will be small.
  142.      */
  143.     if (lrcCount <= LRC_SHORTLIST_SIZE) {
  144.         lrcList = lrcShortList;
  145.     } else {
  146.         lrcList = (LRC*) malloc(lrcCount * sizeof(LRC));
  147.         if (lrcList == NULL) {
  148.             SM_ERROR(TYPE_FATAL, esmMALLOCFAILED);
  149.         }
  150.     }
  151.  
  152.     /*
  153.      *  Store the lrc for each bitmap page in the lrc list
  154.      */
  155.     bm_ListSaveLrc(&bitmapList, lrcList);
  156.  
  157.     /*
  158.      *  Increment the lrc on the volume header
  159.      */
  160.     headerLRC = &(volRec->header->lrc);
  161.     INCREMENT_LRC(headerLRC);
  162.     pageAllocInfo.headerLRC = *headerLRC;
  163.  
  164.     /*
  165.      *    initialize the log information
  166.      */
  167.     recordInfo.type            = LOG_REC_TYPE_COMPENSATION;
  168.     recordInfo.action        = LOG_ACTION_ALLOCATE_PAGE;
  169.     recordInfo.flags        = NOFLAGS;
  170.     recordInfo.imageCount    = 3;
  171.     recordInfo.actionPid    = NULL;
  172.     recordInfo.imageSize[0] = sizeof(PAGEALLOCINFO);
  173.     recordInfo.imageData[0] = (VOID *) &pageAllocInfo;
  174.     recordInfo.imageSize[1] = (unsigned short) 
  175.         sizeof(PID) * (pageAllocInfo.numPages);
  176.     recordInfo.imageData[1] = (VOID *) pidList;
  177.     recordInfo.imageSize[2] = sizeof(LRC) * lrcCount;
  178.     recordInfo.imageData[2] = (VOID *) lrcList;
  179.     recordInfo.flags        = NOFLAGS;
  180.     recordInfo.nextUndoLSN    = recordHeader->previousLSN;
  181.  
  182.     /*
  183.      *    write the record to the log
  184.      */
  185.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  186.                               &lsn, NOFLAGS)) < 0)    {
  187.  
  188.         /*
  189.          *  free any malloced list space and return failure
  190.          */
  191.         if (lrcList != lrcShortList) free((char*)lrcList);
  192.         SM_ERROR(TYPE_FATAL, Active->errno);
  193.     }
  194.  
  195.     /*
  196.      *    release the bitmap pages and mark them
  197.      */
  198.     bm_ListUnfixDepend( &bitmapList, forceMark, &lsn, lrcList );
  199.  
  200.     /*
  201.      *  free any malloced list space
  202.      */
  203.     if (lrcList != lrcShortList) free((char*)lrcList);
  204.  
  205.     /*
  206.      *  Mark the volume header dependency
  207.      */
  208.     DEPEND_LOG(volRec->headerLink->pageHash, forceMark, &lsn, headerLRC);
  209.  
  210.     /*
  211.      *    release the semaphore on the volume header
  212.      */
  213.     signalSemaphore(&(volRec->headerLink->pageHash->semaphore));
  214.  
  215.     /*
  216.      *  Make sure volume is ok
  217.      */
  218. #ifdef DEBUG
  219.     SM_ASSERT(LEVEL_3, !io_Checker(volRec));
  220. #endif
  221. }
  222.